package com.example.springaop.aop.util;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class TestExecutePlatform {
    public static void main(String[] args) throws IOException {
        String requestXml = "{\"msgtype\": \"text\",\"text\": {\"content\":\"我就是我, 是不一样的烟火sb\"}}";
        System.out.println(requestXml);
        CloseableHttpResponse response = null;
        CloseableHttpClient client = null;
        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setSocketTimeout(3000)
                .setConnectTimeout(3000)
                .build();
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        client = httpClientBuilder.setDefaultRequestConfig(defaultRequestConfig).build();

        HttpPost httpPost = new HttpPost("https://oapi.dingtalk.com/robot/send?access_token=f7879cf4c19c8cf93cc7109313b1e6f8d6457e283234d3cdeed462c5c5441eea");
        StringEntity entityParams = new StringEntity(requestXml, "UTF-8");
        httpPost.setEntity(entityParams);
        httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
        response = client.execute(httpPost);
        if (response != null && response.getEntity() != null) {
            String responseXML = EntityUtils.toString(response.getEntity(), "UTF-8");
            System.out.println(responseXML);
        }


    }
}
